#pragma once
#pragma warning(disable:4996)       // disable checked iterator errors http://msdn.microsoft.com/en-us/library/aa985965(VS.80).aspx 

//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101

#include <Macros.h>
#include <CoVector.h>
#include <CoMatrix.h>
#include <CoCube.h>
#include <ValueHelpers.h>
#include <Settings.h>

#include <gen/QL/Models/Marketmodels/CurveState.h>
#pragma unmanaged 
#include <ql\models\marketmodels\curvestates\coterminalswapcurvestate.hpp>
#include <boost/smart_ptr/detail/spinlock.hpp>
#pragma managed 

using namespace System;
using namespace QuantLib;
using namespace Cephei;

using namespace Cephei::QL::Models::Marketmodels;
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
namespace Cephei { namespace QL { namespace Models { namespace Marketmodels { namespace Curvestates {
	//////////////////////////////////////////////////////////////////////////////////////////////
	// implementation of ICoterminalSwapCurveState
	public ref class CCoterminalSwapCurveState : 
            public CCurveState,
            public Cephei::QL::Models::Marketmodels::Curvestates::ICoterminalSwapCurveState
	{
	protected: 
		boost::shared_ptr<QuantLib::CoterminalSwapCurveState>* _ppCoterminalSwapCurveState;
#ifdef HANDLE
		QuantLib::Handle<QuantLib::CoterminalSwapCurveState>* _phCoterminalSwapCurveState;
#endif
		Object^ _CoterminalSwapCurveStateOwner;     // reference to object that manages the storage for this object
	internal:
		CCoterminalSwapCurveState (Cephei::IVector<Double>^ rateTimes);
        CCoterminalSwapCurveState (boost::shared_ptr<QuantLib::CoterminalSwapCurveState>& childNative, Object^ owner);
        CCoterminalSwapCurveState (QuantLib::CoterminalSwapCurveState& childNative, Object^ owner);
        CCoterminalSwapCurveState (CCoterminalSwapCurveState^ copy);
        CCoterminalSwapCurveState (System::Type^ t);
#ifdef STRUCT
        CCoterminalSwapCurveState (QuantLib::CoterminalSwapCurveState childNative);
#endif       
#ifdef HANDLE
		CCoterminalSwapCurveState (QuantLib::Handle<QuantLib::CoterminalSwapCurveState>& childNative, Object^ owner);
		CCoterminalSwapCurveState (QuantLib::Handle<QuantLib::CoterminalSwapCurveState> childNative);
#endif
		virtual ~CCoterminalSwapCurveState ();
		!CCoterminalSwapCurveState ();

	internal:
		QuantLib::CoterminalSwapCurveState& GetReference ();
		boost::shared_ptr<QuantLib::CoterminalSwapCurveState>& GetShared ();
		QuantLib::CoterminalSwapCurveState* GetPointer ();
        void SetCoterminalSwapCurveState (boost::shared_ptr<QuantLib::CoterminalSwapCurveState> native)
        {
            if (_ppCoterminalSwapCurveState != NULL)
                delete _ppCoterminalSwapCurveState;
            _ppCoterminalSwapCurveState = new boost::shared_ptr<QuantLib::CoterminalSwapCurveState> (native);
            SetCurveState (boost::dynamic_pointer_cast<QuantLib::CurveState> (*_ppCoterminalSwapCurveState));
        }
#ifdef HANDLE
		QuantLib::Handle<QuantLib::CoterminalSwapCurveState>& GetHandle ();
#endif
		virtual bool HasNative () override;
    public:
		virtual Double CmSwapAnnuity (UInt64 numeraire, UInt64 i, UInt64 spanningForwards) ;
		virtual Double CmSwapRate (UInt64 i, UInt64 spanningForwards) ;
		virtual Cephei::IVector<Double>^ CmSwapRates (UInt64 spanningForwards) ;
		virtual Double CoterminalSwapAnnuity (UInt64 numeraire, UInt64 i) ;
		virtual Double CoterminalSwapRate (UInt64 i) ;
        property Cephei::IVector<Double>^ CoterminalSwapRates 
        {
		    virtual Cephei::IVector<Double>^ get () ;
        }
		virtual Double DiscountRatio (UInt64 i, UInt64 j) ;
		virtual Double ForwardRate (UInt64 i) ;
        property Cephei::IVector<Double>^ ForwardRates 
        {
		    virtual Cephei::IVector<Double>^ get () ;
        }
		virtual Cephei::QL::Models::Marketmodels::Curvestates::ICoterminalSwapCurveState^ SetOnCoterminalSwapRates (Cephei::IVector<Double>^ swapRates, Microsoft::FSharp::Core::FSharpOption<UInt64>^ firstValidIndex) ;
    };
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// Factory class
	public ref class CCoterminalSwapCurveState_Factory : public System::MarshalByRefObject,  public ICoterminalSwapCurveState_Factory
	{
	public:
        virtual ICoterminalSwapCurveState^ Create (Cephei::IVector<Double>^ rateTimes);
    };
   
/*Cephei*/ } /*QL*/ } /*Models*/ } /*Marketmodels*/ } /*Curvestates */}
